import {FormItemRule} from 'naive-ui'
type formType = "input" | "radio" | "number" | "switch" | "tree" | 'upload' | "select" | "hidden"

export interface ModalFormOption {
  label: string
  value: string | number
}

export interface ModalFormTreeOption{
  label: string
  key: string
  children?: ModalFormTreeOption[]
}

interface ModalFormInitRulesType {
  type?: "array" | "number"
  required: boolean
  message: string
  trigger: "change" | "blur" | ["change", "blur"],
  validator?: (rule: FormItemRule, value: string) => boolean | Error
}

export interface ModalFormInitType {
  type: formType
  value?: string | number
  label: string
  key: string
  rules?: ModalFormInitRulesType | ModalFormInitRulesType[],
  treeOptions?: ModalFormTreeOption | ModalFormTreeOption[]
  options?: ModalFormOption[],
  multiple?: boolean,
  url?: string
}

export type FormModalType<T> = {
  init: (data: ModalFormInitType[]) => void
  validate: () => Promise<T>
}
